package com.learn.security.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.learn.security.mapper.UserMapper;
import com.learn.security.pojo.po.User;
import com.learn.security.pojo.vo.LoginUser;

@Service
public class UserDetailsServiceImpl implements UserDetailsService{

    @Autowired
    private UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        // 1 连接数据库，查询用户信息
        // QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        // queryWrapper.eq("username", username);
        // User user = userMapper.selectOne(queryWrapper); 
        // 自己手动定义，代替连接数据库查询
        User user = new User();
        user.setUsername(username);
        user.setPassword("$2a$10$wdLHeM9RR.EuUDqw1f5EIuIUySz5jsk/WA/WREzSzF4euUvJsh4TK");
        // 2 赋权操作
        List<String> permissions = new ArrayList<>(); // 权限列表
        permissions.add("select");
        permissions.add("delete");
        //
        return new LoginUser(user,permissions);
    }
    
}
